package com.hns.can.base.Exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.hns.frame.enumrate.MsgType;
import com.hns.frame.exception.BusinessException;
public class NologonExceptionController implements HandlerExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		if(ex instanceof BusinessException){
			BusinessException be = (BusinessException)ex;
			if(MsgType.KICK_OFF.getFlag().equals(be.getMsgType())){
				return new ModelAndView(new RedirectView("/login.jsp?login_error=1",true,false,false));
			}
		}
		
		if(request.getSession() == null){
			return new ModelAndView(new RedirectView("/login.jsp?login_error=2",true,false,false));
		}
		return null;
	}
}
